﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace CodeContrib.Tests
{
	[XmlRoot("company", Namespace = "http://www.test.com/ns")]
	public class Company
	{
		private List<Employee> _employees;

		[XmlElement("employee", Order = 3)]
		public List<Employee> Employees
		{
			get
			{
				if (_employees == null)
				{
					_employees = new List<Employee>();
				}

				return _employees;
			}
			set { _employees = value; }
		}

		[XmlElement("id", Order = 0)]
		public Guid Id { get; set; }

		[XmlElement("name", Order = 2)]
		public string Name { get; set; }

		[XmlElement("uri", Order = 1)]
		public string Uri { get; set; }

		public override bool Equals(object obj)
		{
			var other = obj as Company;

			if (other == null)
			{
				return false;
			}

			if (!Equals(Id, other.Id))
			{
				return false;
			}

			if (!Equals(Name, other.Name))
			{
				return false;
			}

			if (!Equals(Uri, other.Uri))
			{
				return false;
			}

			foreach (var employee in Employees)
			{
				if (!other.Employees.Contains(employee))
				{
					return false;
				}
			}

			return true;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}
}